const filterPkg = (pkgObject, ignoreList, subport) => {
  const devObj = {};
  Object.keys(pkgObject).forEach((key) => {
    const isIgnore = ignoreList.some((reg) => {
      return new RegExp(reg).test(key);
    });
    if (isIgnore) {
      return;
    }
    if (subport && key === 'start') {
      // 动态修改 start 命令运行端口号
      devObj[key] = `cross-env PORT=${subport} UMI_ENV=dev umi dev`;
    } else {
      devObj[key] = pkgObject[key];
    }
  });
  return devObj;
};

module.exports = filterPkg;
